package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/13 15:13
 * https://leetcode-cn.com/problems/clumsy-factorial/
 */
public class Title1006 {

    public static int clumsy(int n) {
        return calculate(n, 1);
    }

    public static int calculate(int n, int prefix) {
        if (n <= 2) {
            return prefix * n;
        } else if (n == 3) {
            return prefix * 6;
        } else {
            return prefix * n * (n - 1) / (n - 2) + (n - 3) + calculate(n - 4, -1);
        }
    }

    public static void main(String[] args) {
        int clumsy = clumsy(10);
        System.out.println(clumsy);
    }
}
